using System;
using System.IO;
using System.Threading;

namespace nicotine
{
	public enum TypeAppearance
	{
		Debug = -1,
		Default = 0,
		Header = 1,
		BadAss = 2,
		Terminal = 3
	}
	
	public enum TypeFx
	{
		Earthquake = 1,
		ShortFlash = 2,
		LongFlash = 3,
		Clear = 4,
		Hacked = 5
	}
	
	public static class Typewriter
	{
		public static void WriteLine(TypeAppearance ta, string message)
		{
			processAppearance(ta);
			
			message = message.Replace("\\n", "\n");
			
			int z = 0;
			for (int i = 0; i < message.Length; i++)
			{
				char c = message[i];
				
				if (c == ' ') // Word wrap!
				{
					int i2;
					for (i2 = i + 1; (i2 < message.Length) && (message[i2] != ' ') && (message[i2] != '\n'); i2++) { }
					
					if (z + i2 - i > Console.BufferWidth)
					{
						Console.WriteLine();
						z = 0;
						Thread.Sleep(5);
						continue;
					}
				}
				else if (c == '\n')
					z = 0;
				
				Console.Write(c);
				Thread.Sleep(5);
				z++;
				//z = z % (Console.BufferWidth == 0 ? 80 : Console.BufferWidth);
			}
			
			Console.WriteLine();
			
			Console.ResetColor();
		}
		
		public static void PerformFx(TypeFx tfx)
		{
			switch (tfx)
			{
				case TypeFx.Clear:
					Console.Clear();
					break;
				default:
					throw new NotImplementedException();
			}
		}
		
		private static void processAppearance(TypeAppearance ta)
		{
			switch (ta)
			{
				case TypeAppearance.Debug:
					Console.BackgroundColor = ConsoleColor.Black;
					Console.ForegroundColor = ConsoleColor.Yellow;
					break;
				case TypeAppearance.Default:
					Console.BackgroundColor = ConsoleColor.Black;
					Console.ForegroundColor = ConsoleColor.White;
				 	break;
				case TypeAppearance.Header:
					Console.BackgroundColor = ConsoleColor.Black;
					Console.ForegroundColor = ConsoleColor.Blue;
					break;
			}
		}
	}
}

